<?php
namespace app\expbao\common\controller;

use app\common\controller\Common;
use app\expbao\model\ExUser as ExUserModel;
/**
 * expbao前台公共控制器
 * @package app\expbao\common\controller
 */
class ExApi extends Common
{
    /**
     * 初始化方法
     * @author staroot <394454244@qq.com>
     */
    protected function _initialize()
    {
        // 系统开关
        // if (!config('web_site_status')) {
        //     $this->error('站点已经关闭，请稍后访问~');
        // };
        defined('EID') or define('EID', $this->is_exp_login());
        //define('HINTS')
        //$this->is_exp_api();
        //return json(['data'=>'$datalist','code'=>1,'message'=>'登录成功']);
        //die;
    }
    public function _empty($name)
    {
        //空方法返回数据
        return json(['data'=>'error,function is not exits','code'=>-9,'message'=>'非法访问!您访问了一个不存在的操作']);;
    }
    
     final protected function is_exp_login()
    {
        // 判断是否登录
        if ($eid = is_exp_sign()) {
            // 已登录
            //$eid = '0';
            //echo $eid.'123';
            return $eid;

        } else {
            return false;
            // 未登录
            //var_dump($eid);
            //$this->redirect('expbao/ucenter/login');
        }
    }
    final protected function is_exp_api_login(){
        // echo "string";
        // return json(['data'=>'$datalist','code'=>1,'message'=>'登录成功']);
        // $this->error('站点已经关闭，请稍后访问');
        //die;
        $eid=$this->is_exp_login();
        if ($eid) {
            return true;
        }else{
            return false;
        }
        

    }
    final protected function gethints(){
        $userid=$this->is_exp_login();
        if ($userid) {
            $islogin=true;
            $userinfo=$this->getuserinfo($userid);
            //$userinfo[0]=$userinfo;
            //$userinfo=['userinfo'=>$this->getuserinfo($userid)];
        }else{
            $islogin=false;
            $userinfo=null;
        }
        
        $hints = ['userid'=>$userid,'islogin'=>$islogin,'userinfo'=>$userinfo];
        return $hints;

    }
    final protected function getuserinfo($userid=''){
        $userinfo=ExUserModel::getuserinfo($userid);
        //$userinfo=json_decode($userinfo);
        //$userinfo=ExUserModel::where('id',$userid)->field('id,member_name,member_avatar,member_sex')->select();
        return $userinfo;
    }
    final protected function user_is_login(){
       $userid=$this->is_exp_login();
       //$userinfo=ExUserModel::getuserinfo($userid);
        //$userinfo=json_decode($userinfo);
        //$userinfo=ExUserModel::where('id',$userid)->field('id,member_name,member_avatar,member_sex')->select();
        if ($userid) {
            return $userid;
        }else{
        return false;
        }
    }
}
